var that={}
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
     type:'报道',
      flag: "none"  ,
     address:'',
      markers: [],  //地图参数：
      latitude: "", //纬度 
      longitude: "",  //经度
  },
//获得地图
getMyMap(e) {
  let that = this;
  //自行查询经纬度 http://www.gpsspg.com/maps.htm
  const mapLatitude = 23.1194300000,
        mapLongitude = 113.3212200000;
  wx.getLocation({
    type: 'wgs84', 
    success(res){
    // 当前自己的经纬度 res.latitude，res.longitude
      that.setData({
        latitude: mapLatitude,
        longitude: mapLongitude,
        markers: [{
          id: "0",
          latitude: mapLatitude,
          longitude: mapLongitude,
          iconPath: "https://xcx.quan5fen.com/Public/xcx-hitui/image/imgs-jyh/map-ico.png",
          width: 40,
          height: 40,
          callout: {
            'display': 'ALWAYS', 'fontSize': '30rpx', 'content': '广州珠江新城',
            'padding': '8rpx', 'boxShadow': '0 0 5rpx #333','borderRadius':'4rpx'
          }
        }],
      })

      var locationString = mapLatitude + "," + mapLongitude;
      wx.request({
        url: 'https://apis.map.qq.com/ws/geocoder/v1/',data: {
          "key": "PD5BZ-K2VRO-CPEWZ-SOBAC-4KCDT-KAFLF","location": locationString
        },method: 'GET',success: (r) => {
          //输出一下位置信息  
          console.log('用户位置信息',r.data.result.address);
          that.setData({
            address: r.data.result.address
          })
          //r.data.result.address获得的就是用户的位置信息，将它保存到一个全局变量上  
          getApp().globalData.locationInfo = r.data.result.address;
          //这步是将位置信息保存到本地缓存中，key = value的形式  
          try {
            wx.setStorageSync('locationInfo',r.data.result.address)
          } catch (e) {
            console.log(e)
          }
        }
      });
    }
  })
},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this;
   
    wx.setNavigationBarTitle({ title: '新生报到' })

   
    this.getMyMap()
  
    var uid = wx.getStorageSync('uid');
    wx.request({
      url: app.globalData.baseUrl +'/baodao/getMybaodao', // 仅为示例，并非真实的接口地址
      // url: app.globalData.url.login,
      method: 'post',
      data: {
   
       uid:uid,
        
       
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.code == 0) {
          if(res.data.data.length>0){
            that.setData({

              type: "已报到", //请求结果数据
        
            })
          }
          
        }
  
      }
    }) 
  
  
 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
 qd:function(){
   if(that.data.type=='已报到'){
    wx.showToast({
      title: '已报到',
    })
     return;
   }
  var uid = wx.getStorageSync('uid');
  wx.request({
    url: app.globalData.baseUrl +'/baodao/pubBaodao', // 仅为示例，并非真实的接口地址
    // url: app.globalData.url.login,
    method: 'post',
    data: {
     address:that.data.address,     
     uid:uid,
      
     
    },
    header: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    success: function (res) {
      console.log(res.data);
      if (res.data.code == 0) {
         wx.showToast({
           title: res.data.msg,
         })
        
         that.setData({

          type: "已报到", //请求结果数据
    
        })
      }

    }
  }) 



 },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})